import request from '@/service/request';
import { FILE_URL_PREFIX } from '@/constants/index';

// 注册请求
export function requestUploadFile(file: File) {
  const formData = new FormData();
  formData.append('file', file);

  return request.post<string>({
    url: '/common/upload',
    data: formData,
    interceptors: {
      responseInterceptor(res: any): string {
        return FILE_URL_PREFIX + res?.data;
      },
    },
  });
}

// 修改账户头像
export function requestEditAvatar(params: { avatar: string; id: number }) {
  return request.post<any>({
    url: '/user/editAvatar',
    params,
    interceptors: {
      responseInterceptor(res: any): any {
        return res;
      },
    },
  });
}

export default {};
